<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('sub_account_login_logout_records', function (Blueprint $table) {
            $table->id();

            $table->unsignedInteger('sub_account_id')->comment('子账号id');
            $table->string('sub_account')->comment('店铺名');
            $table->date('log_in_out_date')->comment('记录日期');
            $table->unsignedInteger('record_code')->nullable()->comment('上下号标志: Ymd拼接sub_account_id');
            $table->unsignedInteger('template_id')->nullable()->comment('自定义登记字段模板id');
            $table->unsignedInteger('shop_id')->comment('店铺id');
            $table->string('shop_name')->comment('店铺名');
            $table->integer('department1_id')->nullable()->comment('一级部门id');
            $table->string('department1')->nullable()->comment('一级部门');
            $table->integer('department2_id')->nullable()->comment('二级部门id');
            $table->string('department2')->nullable()->comment('二级部门');
            $table->integer('department3_id')->nullable()->comment('三级部门id');
            $table->string('department3')->nullable()->comment('三级部门');
            $table->integer('department_id')->nullable()->comment('最后一级部门id');
            $table->unsignedInteger('staff_id')->nullable()->comment('客服id');
            $table->string('staff_name')->nullable()->comment('客服名称');
            $table->string('shift_name')->nullable()->comment('班次名称');
            $table->char('on_off_time',16)->nullable()->comment('上下班时间');
            $table->dateTime('login_time')->nullable()->comment('上号时间');
            $table->string('login_certificate')->nullable()->comment('上号凭证');
            $table->string('exception_img')->nullable()->comment('数据异常截图');
            $table->dateTime('logout_time')->nullable()->comment('交班时间');
            $table->text('logout_log')->nullable()->comment('交班日志');
            $table->tinyInteger('is_data_recorded')->default(0)->comment('数据是否已登记，默认0未登记，1已登记');
            $table->tinyInteger('is_forget_login')->default(0)->comment('是否漏上号，默认0否，1是');
            $table->tinyInteger('is_forget_record')->default(0)->comment('是否漏登记，默认0否，1是');

            $table->timestamps();
        });

        \DB::statement("ALTER TABLE `sub_account_login_logout_records` comment '子账号上号下号记录'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('sub_account_login_logout_records');
    }
};
